package com.x.linx.fenfencard.model;

import java.util.ArrayList;
import java.util.List;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

import com.x.linx.fenfencard.model.meta.IRequestCallback;
import com.x.linx.fenfencard.model.meta.InfoOrganize;
import com.x.linx.fenfencard.model.meta.Location;
import com.x.linx.fenfencard.model.meta.ReturnOrganizeList;
import com.x.linx.utils.D;

@EBean
public class Organize {
	@Bean OrganizeProxy mOrganizeProxy;
	
	ArrayList<InfoOrganize> organizeList = new ArrayList<InfoOrganize>();

	// + set & get
	public ArrayList<InfoOrganize> getOrganizeList() {
		return organizeList;
	}
	// - set & get
	
	// + function
	public void getMoreOrgList(Location location, final int limit,
			final IRequestCallback callback){
		D.i("organizeList.size()=" + organizeList.size());
		mOrganizeProxy.listOrg(location, organizeList.size(), limit, new IRequestCallback() {
			@Override
			public void success(Object returnValueObject) {
				ReturnOrganizeList ret = (ReturnOrganizeList)returnValueObject;
				List<InfoOrganize> list = (List<InfoOrganize>)ret.getContent();
				for (InfoOrganize infoOrganize : list) {
					D.i("organizeList.add()");
					organizeList.add(infoOrganize);
				}
				if(null != callback){
					callback.success(list);
				}
			}
			@Override
			public void fail(String errorMessage) {
				if(null != callback){
					callback.fail(errorMessage);
				}
			}
		});
	}
	
	public void clearOrgList(){
		organizeList.clear();
	}
	// - function
	
}
